package com.bishe.bishe.dao.mapper;

import com.bishe.bishe.pojo.Comments;
import com.bishe.bishe.pojo.Feedback;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface FeedbackMapper {

    @Results({
            @Result(property = "feedbackId",column = "feedback_id"),
            @Result(property = "feedbackContent",column = "feedback_content"),
            @Result(property = "feedbackTime",column = "feedback_time"),
            @Result(property = "comments",column = "feedback_comment_id",one = @One(select = "com.bishe.bishe.dao.mapper.CommentMapper.findById")),
    })
    @Select("select * from feedback f,comment c where f.feedback_comment_id=#{commentId} and f.feedback_comment_id=c.comment_id")
    Feedback findByCommentId(@Param("commentId") Integer commentId );

    @Results({
            @Result(property = "feedbackId",column = "feedback_id"),
            @Result(property = "feedbackContent",column = "feedback_content"),
            @Result(property = "feedbackTime",column = "feedback_time"),
            @Result(property = "comments",column = "feedback_comment_id",one = @One(select = "com.bishe.bishe.dao.mapper.CommentMapper.findById")),
    })
    @Select("select * from feedback where feedback_id=#{feedbackId}")
    Feedback findById(@Param("feedbackId") Integer feedbackId );


    @Insert("insert into feedback(feedback_id,feedback_content,feedback_time,feedback_comment_id) value(null,null,null,#{commentId})")
    int insert(@Param("commentId") Integer commentId);

    @Update("update feedback set feedback_content=#{feedback.feedbackContent},feedback_time=#{feedback.feedbackTime} where feedback_id=#{feedback.feedbackId}")
    int update(@Param("feedback") Feedback feedback);
}
